import 'package:flutter/material.dart';
import 'package:flutter_build_env/env/config_wrapper.dart';

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    var config = ConfigWrapper.of(context);

    return new MaterialApp(
      title: 'Flutter Build Env',
      theme: new ThemeData(
        primarySwatch: config.production ? Colors.green : Colors.yellow,
      ),
      home: new MyHomePage(title: 'Flutter Build Env - ${config.env}'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage> {
  final _focusNode = FocusNode();

  @override
  void initState() {
    _focusNode.addListener(() {
      print('111');
      if (!_focusNode.hasFocus) {
        _showMessage();
      }
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    init();
    var apiKey = ConfigWrapper.of(context).apiKey;
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: TextField(
                focusNode: _focusNode,
                keyboardType: TextInputType.phone,
                decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Please enter usernmae',
                    labelText: 'Username'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: TextField(
                keyboardType: TextInputType.emailAddress,
                decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Please enter password',
                    labelText: 'Password'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: TextField(
                keyboardType: TextInputType.text,
                decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: 'Please enter password',
                    labelText: 'Password'),
                ),
              )
          ],
        ),
      ),
      //      body: new Center(child: new Text('API Key : $apiKey')),
    );
  }

  void _showMessage() {
    showDialog<void>(
      context: context,

      barrierDismissible: false, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Text Field lost focus'),
          content: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                Text('Text Field lost focus.'),
              ],
            ),
          ),
          actions: <Widget>[
            FlatButton(
              child: Text('OK'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

  init() {
    print(11);
    List list = [1, 2, 3];
    List lis2 = [5];
    List test = list.map((item) {
      return item + 1;
    }).toList();
    test += lis2;
    print(test);
  }
}
